<?php

error_reporting(E_ALL);

/**
 * HawkModel - BasicVO.php
 *
 * $Id: BasicVO.php,v 1.1.1.1 2007-10-02 13:32:35 rainx Exp $
 *
 * This file is part of HawkModel.
 *
 * Automatic generated with ArgoUML 0.22 on 06.11.2006, 11:26:02
 *
 * @author firstname and lastname of author, <author@example.org>
 */

if (0 > version_compare(PHP_VERSION, '5')) {
    die('This file was generated for PHP 5');
}

/**
 * include VO
 *
 * @author firstname and lastname of author, <author@example.org>
 */
//require_once('VO.php');

//require_once('ModelConfig.php');

//require_once('Logger.php');

/* user defined includes */
// section 127-0-0-1-5ac57385:10ea5f9eca4:-8000:00000000000007F6-includes begin
// section 127-0-0-1-5ac57385:10ea5f9eca4:-8000:00000000000007F6-includes end

/* user defined constants */
// section 127-0-0-1-5ac57385:10ea5f9eca4:-8000:00000000000007F6-constants begin
// section 127-0-0-1-5ac57385:10ea5f9eca4:-8000:00000000000007F6-constants end

/**
 * Short description of class BasicVO
 *
 * @access public
 * @author firstname and lastname of author, <author@example.org>
 */
class BasicVO
        implements VO
{
    // --- ATTRIBUTES ---

    protected $entity = array();

	protected $allows = array();
	
	protected $logger;

    // --- OPERATIONS ---
	//
	
	
	
	/**
	 * @construct
	 *
	 * @param $init you could specify one param as the proto of this value object,
	 * 	if not , a black one will generate
	 **/
	public function __construct($init = false)
	{
		if ($init)
		{
			$this->entity = $init->getEntity();
		}

		$this->logger = Logger::instance();
	}

	function setAllowedKey($allows = array())
	{
		$this->allows = $allows;
	}

    /**
     * get the value of your spcified attribute from VO;
     *
     * @access public
     * @author firstname and lastname of author, <author@example.org>
     * @param $attributeName the name of attribute you wanna get value from 
     * @return the attributeValue if exists ,or false
     */
    public function get($attributeName)
    {
        $returnValue = (string) '';

		if (array_key_exists($attributeName, $this->entity))
		{
			$returnValue = $this->entity[$attributeName];
		}
		else
		{
			return false;
		}
        return (string) $returnValue;
    }

    /**
     * get attribute of VO
     *
     * @access public
     * @author firstname and lastname of author, <author@example.org>
     * @param $attributeName the attribute to be set
     * @param $attributeValue the value to be specified attribute
     * @return if set value that if has already exists in array , return true ,else false
     */
    public function set($attributeName, $attributeValue)
    {
        $returnValue = (bool) false;

		if (!in_array($attributeName, $this->allows))
		{
			return C_MODEL_VO_NOT_ALLLOWED_KEY;
		}

		if (array_key_exists($attributeName, $this->entity))
		{
			$returnValue = (bool) true;
		}
		$this->entity[$attributeName] = $attributeValue;

        return (bool) $returnValue;
    }

	/**
	 * remove attribute from VO
	 *
	 * @param  $attributeName the name of attribute to be removed
	 * @return if that attribute wasn't here,return false , else true
	 */
	public function remove($attributeName)
	{
		$returnValue = (bool) false;
		if (array_key_exists($attributeName, $this->entity))
		{
			unset($this->entity[$attributeName]);
		}

		return (bool) $returnValue;
	}

	/**
	 * get entity of the ValueObject
	 * 
	 * @return entity array in vo
	 */
	public function getEntity()
	{
		return $this->entity;
	}
	
	/**
	 * set entity with a array
	 *
	 * @param $entity the entity to be set
	 */
	public function setEntity($entity)
	{
		return $this->entity = $entity;
	}

	/**
	 * Merge two array;
	 * 
	 * @param $i array to be merged 
	 * @param $j another array
	 */
	public function &arrayMerge(&$i, &$j)
	{
		foreach ($j as $key)
		{
			if (!in_array($key, $i))
			{
				$i[] = $key;
			}
		}
		return $i;
	}


} /* end of abstract class BasicVO */

?>
